<html>
<head><meta charset="utf-8"><title>const-prop post insantiation · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html">const-prop post insantiation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182408292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182408292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giovanni Bajo <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182408292">(Dec 03 2019 at 01:36)</a>:</h4>
<p>Hi! About the constant propagation: I have a large generic that can benefit from it a lot but post-instantiation. Is this something that the new pass will still improve? Or does it only work pre-instantiation?</p>



<a name="182409463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182409463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182409463">(Dec 03 2019 at 02:01)</a>:</h4>
<p><span class="user-mention" data-user-id="252458">@Giovanni Bajo</span> MIR optimizations are currently just pre-instantiation so it's unlikely to help. If you can provide a sample though, we can test and verify for sure.</p>



<a name="182409935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182409935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182409935">(Dec 03 2019 at 02:12)</a>:</h4>
<p>Actually, let me walk some of that back. Even in a generic function, we can sometimes still perform optimizations in a generic context. If you can link to the code, I'd be happy to take a look. That may also give us some ideas for future improvements or other optimizations.</p>



<a name="182421982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182421982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182421982">(Dec 03 2019 at 07:11)</a>:</h4>
<p>Also once it gets inlined into a less generic context we can optimize there</p>



<a name="182612860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182612860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giovanni Bajo <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182612860">(Dec 04 2019 at 23:48)</a>:</h4>
<p>[]</p>



<a name="182613099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/const-prop%20post%20insantiation/near/182613099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Giovanni Bajo <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/const-prop.20post.20insantiation.html#182613099">(Dec 04 2019 at 23:50)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="252458">Giovanni Bajo</span> MIR optimizations are currently just pre-instantiation so it's unlikely to help. If you can provide a sample though, we can test and verify for sure.</p>
</blockquote>
<p>The code is a MIPS64 interpreter (part of my Nintendo64 emulator). The MIPS architecture consists of several generation where new opcodes were added (and sometimes removed) over the years. The interpreter core is a generic parametrized over a trait which describes the architecture. Since each architecture can basically disable specific opcodes, and (for performance reasons too long to explain) I don't have an enum representing each opcode, I ended up using a function called with literal strings.</p>
<p>Example of opcode:<br>
<a href="https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/cpu.rs#L314" target="_blank" title="https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/cpu.rs#L314">https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/cpu.rs#L314</a></p>
<p>Example of architecture disabling opcodes:<br>
<a href="https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/arch.rs#L55" target="_blank" title="https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/arch.rs#L55">https://github.com/rasky/r64emu/blob/74c82c6b0e90c2efd7fbe613944f0fd9807ec90b/emu/cpu/mips64/src/arch.rs#L55</a></p>
<p>All the has_op function called are removed by LLVM optimizer, but I'm sure it generates lots of code that is then removed.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>